package prototype

import "utilx/logx"

//原型接口

// 具体原型

type Inode interface {
	print(string)
	clone() Inode
}
type File struct {
	name string
}

func (f *File) print(indentation string) {
	logx.Debug(indentation + f.name)
}

// 创建文件克隆
func (f *File) clone() Inode {
	return &File{name: f.name + "_clone"}
}

type Folder struct {
	children []Inode
	name     string
}

func (f *Folder) print(indentation string) {

	logx.Warn(indentation + f.name)
	for _, i := range f.children {
		i.print(indentation + indentation)
	}
}

// 创建文件夹克隆

func (f *Folder) clone() Inode {
	cloneFolder := &Folder{name: f.name + "_clone"}
	var tempChildren []Inode
	for _, i := range f.children {
		copy := i.clone()
		tempChildren = append(tempChildren, copy)
	}
	cloneFolder.children = tempChildren
	return cloneFolder
}
